package com.jpsl.core.util;

import java.util.Collection;
import java.util.Map;

/**
 * @author 懒王猫
 */
public abstract class Assert {

    /**
     * expectation = false 时抛异常
     * 
     * @param expectation 期望结果为 true
     * @param message 异常信息
     * @throws RuntimeException
     */
    public static void isTrue(boolean expectation, String message) {
        if (!expectation) {
            throw new RuntimeException(message);
        }
    }

    public static void notNull(Object o, String name) {
        isTrue(o != null, name + "不能为Null");
    }

    public static void notEmpty(CharSequence cs, String name) {
        isTrue(cs != null && cs.length() > 0, name + "不能为空");
    }

    public static void notEmpty(Collection<?> collection, String name) {
        isTrue(CollectionUtil.isNotEmpty(collection), name + "不能为空");
    }

    public static void notEmpty(Map<?, ?> map, String name) {
        isTrue(CollectionUtil.isNotEmpty(map), name + "不能为空");
    }

    public static <T> void notEmpty(T[] array, String name) {
        isTrue(CollectionUtil.isNotEmpty(array), name + "不能为空");
    }

}
